﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CoolERP_BLL;
using CoolERP_Entities;

namespace CoolERP_Web.User
{
    public partial class MenuMgr : BasePage
    {
        static List<Menus> itemLists = new List<Menus>();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }

        private void BindData()
        {
            using (MenusBLL mBLL = new MenusBLL())
            {
                itemLists = mBLL.GetList(null, "Code,Sort desc");
                Repeater1.DataSource = itemLists.Where(t => t.ParentId == null);
                Repeater1.DataBind();
                panMsg.Visible = itemLists.Count == 0;
            }
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(hidDelIds.Value))
            {
                using (MenusBLL mBLL = new MenusBLL())
                {
                    mBLL.Deletes("Id", hidDelIds.Value);
                }
            }
            Referer();
        }

        protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.DataItem != null)
            {
                Repeater rep = e.Item.FindControl("repChild") as Repeater;
                Menus item = e.Item.DataItem as Menus;
                rep.DataSource = itemLists.Where(t => t.ParentId == item.Id);
                rep.DataBind();
            }
        }
    }
}